package me.riddhimanadib.formmaster.viewholder;

import android.content.Context;
import android.view.View;

import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.AppCompatTextView;
import me.riddhimanadib.formmaster.R;
import me.riddhimanadib.formmaster.model.BaseFormElement;

/**
 * ViewHolder for Header
 * Created by Riddhi - Rudra on 30-Jul-17.
 */

public class FormElementHeader extends BaseViewHolder {
    public interface OnAddButtonClicked {
        public void clicked();
    }

    public AppCompatTextView    mTextViewTitle;
    public AppCompatImageButton button;
    OnAddButtonClicked listener;

    public FormElementHeader(View v, OnAddButtonClicked listener) {
        super(v);
        this.listener = listener;
        mTextViewTitle = (AppCompatTextView) v.findViewById(R.id.formElementTitle);
        button = v.findViewById(R.id.formElementTitleAddButton);
    }

    @Override
    public void bind(int position, BaseFormElement formElement, final Context context) {
        mTextViewTitle.setText(formElement.getTitle());
        if (button == null) {
            return;
        }

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.clicked();
                }
            }
        });
    }
}
